<?php
/**
 * 日记 (评论、阅读、笑脸数目)
 * @author  zhanghui
 * @create_date 2008-02-26
 */

class DiaryCnt{
    function __construct(){}
    
    function __destruct(){}
    
    /* 增加评论数  
     * @param : $arr_input - baby_id,postid,comment_cnt
     */
    public function updateCommentCnt($conn,$arr_input){
        $str_query = "update";
        $str_query .= " baby_diary_cnt";
        $str_query .= " set";
        $str_query .= " comment_cnt=comment_cnt+{$arr_input['comment_cnt']}";
        $str_query .= " where";
        $str_query .= " baby_id={$arr_input['baby_id']}";
        $str_query .= " and postid={$arr_input['postid']}";
        
        $conn->executeQuery($str_query);
    }
    
    /* 增加阅读数  
     * @param : $arr_input - baby_id,postid,read_cnt
     */
    public function increaseReadCnt($conn,$arr_input){
        $str_query = "update";
        $str_query .= " baby_diary_cnt";
        $str_query .= " set";
        $str_query .= " read_cnt=read_cnt+1";
        $str_query .= " where";
        $str_query .= " baby_id={$arr_input['baby_id']}";
        $str_query .= " and postid={$arr_input['postid']}";
        
        $conn->executeQuery($str_query);
    }
    
    /* 增加笑脸数  
     * @param : $arr_input - baby_id,postid,smile_cnt
     */
    public function increaseSmileCnt($conn,$arr_input){
        $str_query = "update";
        $str_query .= " baby_diary_cnt";
        $str_query .= " set";
        $str_query .= " smile_cnt=smile_cnt+1";
        $str_query .= " where";
        $str_query .= " baby_id={$arr_input['baby_id']}";
        $str_query .= " and postid={$arr_input['postid']}";
        
        $conn->executeQuery($str_query);
    }
    
    /*  取得评论、阅读、笑脸的数目 */
    public function getDiaryCntList($conn,$arr_input,$limit = null){
    	$str_query = "select";
    	$str_query .= " comment_cnt";
    	$str_query .= ",read_cnt";
    	$str_query .= ",smile_cnt";
    	$str_query .= " from";
    	$str_query .= " baby_diary_cnt";
    	$str_query .= " where";
    	$str_query .= " baby_id={$arr_input['baby_id']}";
    	
		if (isset($arr_input['postid'])){
			$str_query .= " and postid={$arr_input['postid']}";
		}
		if (isset($arr_input['orderby'])) {
    		$str_query .= " order by {$arr_input['orderby']}";
    	}

    	if ($limit != null){
    		$str_query .= " {$limit}";
    	}
        
        $arr_output = $conn->selectQuery($str_query);
        return $arr_output;
    }
    
    /* 增加一条数目记录 
     * @param : $arr_input - baby_id,postid,comment_cnt,read_cnt,smile_cnt
     */
    function initDiaryCnt($conn,$arr_input){
    	$str_query = "insert into";
    	$str_query .= " baby_diary_cnt";
    	$str_query .= " set";
    	$str_query .= " baby_id={$arr_input['baby_id']}";
    	$str_query .= ",postid={$arr_input['postid']}";
    	
    	$conn->executeQuery($str_query);
    }
    
    /* 删除一条数目记录 
     * @param : $arr_input - baby_id,postid,comment_cnt,read_cnt,smile_cnt
     */
    function deleteDiaryCnt($conn,$arr_input){
    	$str_query = "delete from";
    	$str_query .= " baby_diary_cnt";
    	$str_query .= " where";
    	$str_query .= " baby_id={$arr_input['baby_id']}";
    	$str_query .= " and postid={$arr_input['postid']}";
    	
    	$conn->executeQuery($str_query);
    }
}
?>